package com.itcam.lease.web.admin.service.impl;

import com.itcam.lease.model.entity.SystemPost;
import com.itcam.lease.model.entity.SystemUser;
import com.itcam.lease.web.admin.mapper.SystemPostMapper;
import com.itcam.lease.web.admin.mapper.SystemUserMapper;
import com.itcam.lease.web.admin.service.SystemUserService;
import com.itcam.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.itcam.lease.web.admin.vo.system.user.SystemUserQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {

    @Autowired
    private SystemUserMapper systemUserMapper;

    @Autowired
    private SystemPostMapper systemPostMapper;


    /**
     * 根据条件分页查询后台用户列表
     * @param page
     * @param queryVo
     * @return
     */
    @Override
    public IPage<SystemUserItemVo> pageSystemUserByQuery(IPage<SystemUser> page, SystemUserQueryVo queryVo) {
        return systemUserMapper.pageSystemUserByQuery(page, queryVo);
    }

    /**
     * 根据ID查询后台用户信息
     * @param id 用户id
     * @return 用户信息
     */
    @Override
    public SystemUserItemVo getSystemUserById(Long id) {
        // 根据id查询用户信息
        SystemUser systemUser = systemUserMapper.selectById(id);
        // 根据用户的岗位id查询岗位信息
        SystemPost systemPost = systemPostMapper.selectById(systemUser.getPostId());
        // 创建一个新的 SystemUserItemVo 对象，用于封装用户的详细信息
        SystemUserItemVo systemUserItemVo = new SystemUserItemVo();
        // 将岗位信息复制到 SystemUserItemVo 对象中
        BeanUtils.copyProperties(systemPost, systemUserItemVo);
        // 设置岗位名称
        systemUserItemVo.setPostName(systemUserItemVo.getPostName());
        // 返回封装好的用户详细信息对象
        return systemUserItemVo;
    }

}




